<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="../static/css/bootstrap.css" />
    <!--需要在Javascript之前引入JQuer-->
    <script type="text/javascript" src="../static/js/jquery-1.11.0.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script type="text/javascript" src="../static/js/bootstrap.js"></script>
    <!--针对移动设备的样式，为了确保适当的绘制和触屏缩放-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--jquery.cookie.js-->
    <script src="../static/js/jquery.cookie.js"></script>
    <script>
    </script>
</head>
<body>
  <div class="container-fluid" style="padding: 30px 300px;">
     <div class="row-fluid jumbotron">
         <span style="float: right;">
             <a href="/content/detail">
                 <span class="glyphicon glyphicon-home"> 首页</span>
             </a>
         </span>
         <span id="return" hidden>
             <a href="/userlist">
                 <span class="glyphicon glyphicon-chevron-left"> 返回</span>
             </a>
         </span>
            <div class="row-fluid">
                <div class="span12">
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="page-header">
                                <h1>
                                    个人资料
                                </h1>
                            </div>
                        </div>
                    </div>
                    <div class="container">
                        <div class="row clearfix">
                            <div class="col-md-12 column">
                                <input type="file" id="InputImgFile"  style="display: none"/>
                                <form role="form" action="/user/edit" method="post" enctype="multipart/form-data">
                                    <div class="form-group">
                                        <label for="InputImgFile">
                                            <img alt="140x140" src="../static/img/header/user.PNG" class="img-circle" width="140px" height="140px"/>
                                        </label>
                                        <input type="text" id="ImgName" name="InputImgFile" value="" style="display: none" accept="image/*" required/>
                                        <p class="help-block">
                                            点击你的头像！<font color="blue">{{.suceese}}{{.ext}}</font>
                                        </p>
                                        <span id="del" style="float: right;"></span>
                                    </div>
                                    <script>
                                        InputImg();
                                        function InputImg() {
                                            $("#InputImgFile").change(function () {
                                                $(".img-circle").cite;
                                                var Inputimg = $(this).val().slice(12,);
                                                $("#ImgName").val(Inputimg);
                                                var imgUrl = "../static/img/header/"+Inputimg;
                                                $(".img-circle").attr("src" , imgUrl);
                                            });
                                        };
                                    </script>
                                    <div class="form-group" style="display: none;">
                                        <label for="ID">ID</label><input type="text" class="form-control" id="id" name="id"id="id" required/>
                                    </div>
                                    <div class="form-group">
                                        <label for="NAME">姓名</label><input type="text" id="name" name="name" class="form-control" id="InputName" minlength="1" maxlength="10" required/>
                                    </div>
                                    <div class="form-group">
                                        <label for="PASSWD">密码</label><input type="text" id="passwd" name="passwd" class="form-control" id="InputPassword1" minlength="6" maxlength="11" required/>
                                    </div>
                                    <div class="form-group">
                                        <label for="SEX">性别</label>
                                        <br />
                                        <label class="radio-inline">
                                            <input type="radio" name="sex" id="sexRadio1" value="男"> 男
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="sex" id="sexRadio2" value="女"> 女
                                        </label>
                                    </div>
                                    <div class="form-group">
                                        <label for="STATUS">状态</label>
                                        <br />
                                        <label class="radio-inline">
                                            <input type="radio" name="sta" id="staRadio1" value="0"> 已激活
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="sta" id="staRadio2" value="1"> 已禁言
                                        </label>
                                    </div>
                                    <script>
                                        $(function () {
                                            var su = $.cookie("login_username");
                                            // alert(su);
                                            if(su === "admin"){
                                                $("input[type='radio']").prop({
                                                    disabled: false
                                                });
                                                $("#return").prop({hidden:false});
                                            }else {
                                                $("input[type='radio']").prop({
                                                    disabled: true
                                                });
                                                $("#return").prop({hidden:true});
                                            }
                                            // //关闭cookie
                                            // setTimeout(function(){
                                            //     $.cookie("login_username",null)},300000);
                                        });
                                    </script>
                                    <div style="float: right;">
                                        <button type="submit" class="btn btn-default">提交修改</button>
                                    </div>
                                    <script>
                                        //  表单绑定事件
                                        $("form").submit(function() {
                                            $("input[type='radio']").removeProp("disabled");
                                            return true;
                                        });
                                    </script>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
     </div>
</body>
<script>
    $(function(){
        var id = $.cookie("upuser");
        var url = "/user/getone?id="+id;
        $.get(url, function(data, status) {
            console.log(data)
            $("#id").val(data.id)
            $("#name").val(data.name)
            if (data.pic.length>0){
                $(".img-circle").cite;
                var imgUrl = "../static/img/header/"+data.pic;
                $(".img-circle").attr("src" , imgUrl);
                var imgName = $(".img-circle").attr("src").slice(21,);
                $("#ImgName").val(imgName);
            }
            if(data.sex === "男"){
                $("#sexRadio1").prop("checked",true);
                $("#sexRadio2").prop("checked",false);
            }else{
                $("#sexRadio1").prop("checked",false);
                $("#sexRadio2").prop("checked",true);
            }
            if(data.sta === "0"){
                $("#staRadio1").prop("checked",true);
                $("#staRadio2").prop("checked",false);
            }else{
                $("#staRadio1").prop("checked",false);
                $("#staRadio2").prop("checked",true);
            }
            $("#del").html("<a href='#' onclick='Trash("+data.id+") ' ><font color='#9932cc;'>注销账号!</font></a>")
      });
        $.removeCookie("upuser");
    });
    //删除用户
    function Trash(id) {
        var delUrl = "/user/del?id="+id;
        $.post(delUrl,function (success) {
            alert("注销成功！");
            window.location.reload();
        })
    }
    $(function () {
        var StaVal = $.cookie("up");
        if (StaVal == "fail"){
            alert("修改失败，用户名已存在！");
            $.removeCookie("register");
        }
    });
</script>
</html>